/**
 * Copyright (c) 2012 Axa Holding Belgium, SA. All rights reserved.
 * This software is the confidential and proprietary information of the AXA Group.
 */
package chabernac.android.wordbattle.paint.bogglesimple;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.view.View;
import chabernac.android.wordbattle.WordBattleView;
import chabernac.android.wordbattle.model.Letter;
import chabernac.android.wordbattle.model.Word;
import chabernac.android.wordbattle.paint.iDrawable;

public class SelectedWordDrawable extends iDrawable {
  private final Word myWord;
  private Paint myPaint;

  public SelectedWordDrawable( Word aWord ) {
    myWord = aWord;
    init();
  }
  
  private void init(){
    myPaint = new Paint();
//    myPaint.setColor( Color.argb(255,100,100,200) );
    
    
  }

  @Override
  public void paint( Canvas aCanvas, View aView ) {
    WordBattleView theView = (WordBattleView)aView;
    
    myPaint.setStrokeWidth( (float)(theView.getWidthPerColumn() * 0.2));
    
    Letter thePreviousLetter = null;
    float thePreviousCenterX = -1;
    float thePreviousCenterY = -1;
    for(Letter theLetter : myWord.getLetters()){
      
      float theCenterX = (float)(WordBattleView.BORDER_SIZE + (theLetter.getColumn() + 0.5) * theView.getWidthPerColumn());
      float theCenterY = (float)(WordBattleView.BORDER_SIZE + (theLetter.getRow() + 0.5) * theView.getHeightPerRow());
      
      if(thePreviousLetter != null){
        //draw a rectangle from the center of the previsou letter to the center of this letter
        myPaint.setShader(new LinearGradient(thePreviousCenterX, thePreviousCenterY, theCenterX, theCenterY, Color.argb(255,100,255,255), Color.argb(255,100,100,200), Shader.TileMode.MIRROR));
        aCanvas.drawLine(thePreviousCenterX, thePreviousCenterY, theCenterX, theCenterY, myPaint);
      }
      
      thePreviousLetter = theLetter;
      thePreviousCenterX = theCenterX;
      thePreviousCenterY = theCenterY;
    }
  }

}
